#!/usr/bin/perl

use strict;
use MeCab;
use CGI;

print "Content-Type: text/html\n\n";



my $cgi = new CGI;


print <<HTMLHEAD;
<html>
<body>
HTMLHEAD

my $str = "この文を形態素解析して下さい。";


my $getstring = $cgi->param('str');

$getstring =~ s/<//g;
$getstring =~ s/>//g;
$getstring =~ s/\.\.//g;
$getstring =~ s/$//g;

if( (length $getstring) != 0){$str=$getstring;}

#print $getstring;

print <<FORM;
<form method="GET" action="mecab_wakati.cgi">
文章：<input type="text" name="str" size="50"></p>
<input type="submit" value="解析" />
</form>
FORM


my $mecab = MeCab::Tagger->new();
my $node = $mecab->parseToNode($str);
print "[ ",$str," ]を形態素解析します<br><br>";

print "見出し / 読み / 品詞<br>";
for( ; $node; $node = $node->{next} ) {
    next unless defined $node->{surface};
    my $midasi = $node->{surface};
    my( $hinsi, $yomi ) = (split( /,/, $node->{feature} ))[0,7];
    #print $midasi, "\t", $yomi, "\t", $hinsi, "\n";
    print $midasi, " /  ", $yomi, " /  ", $hinsi, "<br>";
}

print <<HTMLFOOT;
</body>
</html>
HTMLFOOT
